import { setStorage, getStorage } from '@/common/utils/utils'
import { _branchData, _brandData } from './test-beta.js'
const tags = getStorage('examTags') || []
const branchData = getStorage('branchData') || _branchData
const brandData = getStorage('companyDataNow') || _brandData

interface stateType {
  currentTags: Array<object>;
  askingPath: string;
  needClosePath: string;
  brandData: {
    orgLevelId: string;
    [propName: string]: any;
  }
  branchData: {
    cityCode: string;
    orgLevelId: string;
    [propName: string]: any;
  }
}

export default {
  state: {
    currentTags: [...tags], //当前打开的tag
    askingPath: '', // 当前问询是否要关闭页面
    needClosePath: '', //需要关闭的页面
    brandData, // 当前导航选择的总公司
    branchData
  },
  mutations: {
    setCurrentTags(state: stateType, data: Array<object>) {
      state.currentTags = data;
      setStorage('examTags', data)
    },
    setAskingPath(state: stateType, fullPath: string) {
      state.askingPath = fullPath
    },
    updateComponyData(state: stateType) { // 更新分公司信息
      if (import.meta.env.PROD) { // 仅 prod 环境 执行 
        let branchData = getStorage('branchData') || {}
        let brandData = getStorage('companyDataNow') || {}
        if (
          branchData.orgLevelId !== state.branchData.orgLevelId ||
          brandData.orgLevelId !== state.brandData.orgLevelId
        ) {
          // store.commit('setCurrentTags', [])
          location.href = '/exam/'
        }
      }
    }
  }
}